package ma.zhiqiang.dataline.core.format;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import ma.zhiqiang.dataline.core.dto.Column;
import ma.zhiqiang.dataline.core.dto.ColumnMap;
import ma.zhiqiang.dataline.core.dto.SinkRecord;

public class WriterFormatJson implements WriterFormat{
    @Override
    public String format(SinkRecord sinkRecord) {
        ColumnMap<String, Column> columnMap = (ColumnMap<String, Column>) sinkRecord.getData();
        JSONObject object = new JSONObject();
        columnMap.values().forEach(column -> {
            object.putOnce(column.getAlias(),column.getValue());
        });
        return JSONUtil.toJsonStr(object);
    }
}
